﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SuperBall3D
{
    public partial class LevelEditor : Form
    {

        private SuperBallGame gme;


        public LevelEditor(SuperBallGame game)
        {
            gme = game;
            InitializeComponent();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            propertyGrid1.SelectedObject = gme.Components[listBox1.SelectedIndex];
        }
        

        private void button1_Click(object sender, EventArgs e)
        {
            RefreshBox();
        }

        private void RefreshBox()
        {
            listBox1.Items.Clear();
            var components = gme.Components.ToArray();
            String[] names = new string[gme.Components.Count];
            for (int i = 0; i < names.Length; i++)
            {
                names[i] = i.ToString() + " " + components[i].GetType().Name;
            }
            listBox1.Items.AddRange(names);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            using (StreamWriter writer = new StreamWriter("addToLevel.cs"))
            {
                writer.Write("using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace SuperBall3D {     public partial class SuperBallGame : Microsoft.Xna.Framework.Game    {        private void Generate()         {");            
                foreach (SuperBallObject component in gme.Components)
                {
                    writer.Write(component.GenerateConstructor());
                }
                writer.Write("}     } }");
            }
        
        }

    }
}
